package com.github.shiqiyue.app.config.security.sapi;


import com.github.shiqiyue.app.common.result.Result;
import com.github.shiqiyue.app.common.result.ResultCode;
import com.github.shiqiyue.app.common.result.ResultMsg;
import com.github.shiqiyue.app.common.utils.ResponseUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/***
 * 后台用户未登录，访问拒绝
 * @author wenyao.wu
 */
public class SapiAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        //未登录，访问拒绝
        ResponseUtils.populateResponse(
                ResponseEntity.ok(Result.newInstance(ResultMsg.CAN_NOT_ACCESS, ResultCode.NOT_LOGIN)),
                httpServletResponse);
    }
}
